package demo3;

class Animal {
    public String name;
    public int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
}
//接口
interface IRun {
    void run();
}
interface IFly {
    void fly();
}
interface ISwim {
    void swim();
}

class Dog extends Animal implements IRun {
    public Dog(String name, int age) {
        super(name, age);
    }
    public void run() {
        System.out.println(this.name + " 这条狗正在跑！");
    }
}

class Duck extends Animal implements IRun, ISwim, IFly {
    public Duck(String name, int age) {
        super(name, age);
    }
    public void run() {
        System.out.println(this.name + " 这只鸭正在跑！");
    }
    public void fly() {
        System.out.println(this.name + " 这只鸭正在飞！");
    }
    public void swim() {
        System.out.println(this.name + " 这只鸭正在游泳！");
    }
}

class Frog extends Animal implements IRun, ISwim {
    @Override
    public void run() {
        System.out.println(this.name + " 这只蛙正在跑！");
    }
    @Override
    public void swim() {
        System.out.println(this.name + " 这只蛙正在游泳！");
    }
    public Frog(String name, int age) {
        super(name, age);
    }
}



public class Test {

    public static void walk(IRun iRun) {
        System.out.println("我带着伙伴去散步");
        iRun.run();
    }

    public static void Running(IRun iRun) {
        iRun.run();
    }
    public static void Flying(IFly iFly) {
        iFly.fly();
    }
    public static void Swiming(ISwim iSwim) {
        iSwim.swim();
    }

    public static void main(String[] args) {
        Running(new Dog("二狗子", 2));
        Running(new Duck("唐老鸭", 3));
        Running(new Frog("青蛙", 1));
        Swiming(new Duck("唐老鸭", 3));
        Swiming(new Frog("青蛙", 1));
        Flying(new Duck("唐老鸭", 3));

        Dog dog = new Dog("小狗",2);
        walk(dog);
        Frog frog = new Frog("小青蛙",1);
        walk(frog);
    }
}
